package LeetCode;

import java.util.*;
class A{
    int a=0;
}
public class LeetCodeMain21 {
    public static void main(String[] args) {
        List<Integer> list=new ArrayList<>(5);
        System.out.println(list.size());
    }
    public int findContentChildren(int[] g, int[] s) {
        int count=0;
        Arrays.sort(g);
        Arrays.sort(s);
            for (int j = 0; j < s.length; j++) {
                if (count<g.length&&g[count]<=s[j]){
                    count++;
                }
            }

        return count;
    }
    public int wiggleMaxLength1(int[] nums) {
        List<Integer> list=new ArrayList<>();
        if (nums.length>2){
            for (int i = 0; i < nums.length-1; i++) {
                int sum=nums[i+1]-nums[i];
                if (list.isEmpty()&&sum!=0){
                    list.add(sum);
                }else if (sum!=0){
                    int sum1=list.get(list.size()-1);
                    if (sum1>0&&sum<0){
                        list.add(sum);
                    }else if (sum1<0&&sum>0){
                        list.add(sum);
                    }
                }
            }
        }
        return list.size()+1;
    }
    public int wiggleMaxLength(int[] nums) {
        if (nums.length<2) {
            return nums.length;
        }
        int left=0;
        int right=0;
        int res=1;
        for (int i = 0; i < nums.length-1; i++) {
            right=nums[i+1]-nums[i];
            if ((left<=0&&right>0)||(left>=0&&right<0)){
                res++;
                left=right;
            }
        }
        return res;
    }
    public int maxDepth(String s) {
        int max=0;
        int count=0;
        int length=s.length();
        int i=0;
        while (i<length){
            max=Math.max(max,count);
            if (s.charAt(i)=='('){
                count++;
            }else if (s.charAt(i)==')'){
                count--;
            }
            i++;
        }
        return count;
    }
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack=new Stack<>();
        for (String token:tokens) {
            if (isNumber(token)){
                stack.push(Integer.parseInt(token));
            }else {
                int num2=stack.pop();
                int num1=stack.pop();
                switch (token){
                    case "+":
                        stack.push(num1+num2);
                        break;
                    case "-":
                        stack.push(num1-num2);
                        break;
                    case "*":
                        stack.push(num1*num2);
                        break;
                    case "/":
                        stack.push(num1/num2);
                        break;
                }
            }
        }
        return stack.pop();
    }
    public boolean isNumber(String token){
        return !("+".equals(token)||"-".equals(token)||"*".equals(token)||"/".equals(token));
    }
    public int calPoints(String[] ops) {
        String str[]=ops;
        int num1,num;
        Stack<Integer> stack=new Stack<>();
        for (String s:str) {
            if ("+".equals(s)) {
                num1 = stack.pop();
                num = num1 + stack.peek();
                stack.push(num1);
                stack.push(num);
            } else if ("D".equals(s)) {
                num = stack.peek() * 2;
                stack.push(num);
            } else if ("C".equals(s)) {

                stack.pop();
            } else {
                stack.push(Integer.valueOf(s));
            }
        }
        int sum=0;
        while (!stack.isEmpty()){
            sum+=stack.pop();
        }
        return sum;
    }
    public int[] finalPrices(int[] prices) {
        int[] price=new int[prices.length];
        for (int i = 0; i < prices.length; i++) {
            int flag=0;
            for (int j = i+1; j < prices.length; j++) {
                if (j>i&&prices[i]>=prices[j]){
                    flag=prices[j];
                    break;
                }
            }
            price[i]=prices[i]-flag;
        }
        return price;
    }
    public int firstUniqChar(String s) {
        HashMap<Character,Integer> map=new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char ch=s.charAt(i);
            if (map.containsKey(ch)){
                int value=map.get(ch);
                map.put(ch,value+1);
            }
            else {
                map.put(ch,1);
            }
        }

        for (int i = 0; i < s.length(); i++) {
            char ch=s.charAt(i);
            if (map.get(ch)==1){
                return i;
            }
        }
        return -1;
    }
    List<Integer> list=new ArrayList<>();
    int listsize=0;
//    public MovingAverage(int size) {
//        listsize=size;
//    }
    public double next(int val) {
        int sum=0;
        if (list.size()<listsize){
            list.add(val);
        }else if (listsize==list.size()){
            list.remove(0);
            list.add(val);
        }
        for (Integer num:list) {
            sum+=num;
        }
        return (double)sum/list.size();
    }
}
